package com.anli.lockCelue;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.anli.leguansuo.LeGuanSuoService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/9  9:33
 * 描述:
 */
@Component
public class LeGuanLockCeLue implements LockCeLue{

    @Autowired
    private LeGuanSuoService leGuanSuoService;

    @Override
    public void lockCelue(String json) {

        JSONObject jsonObject = JSON.parseObject(json);
        leGuanSuoService.updateStock(jsonObject.getString("goodsId"),jsonObject.getIntValue("lockStock"));

    }

    /**
     * 作者: LCG
     * 日期: 2021/3/9  9:34
     * 描述: 实例化bean的时候完成策略的注册
     * @Param []
     * @Return void
     */
    @PostConstruct
    public void afterPropertiesSet(){
        LockCeLueFactory.ceLueRegister("LEGUAN-LOCK1",this);
    }
}
